package com.design;

import java.util.concurrent.atomic.AtomicReference;

/**
 * CAS方式实现
 */
public class Singleton06 {
    private static final AtomicReference<Singleton06> INSTANCE = new AtomicReference<>();

    public Singleton06 getSingleton06(){
        while (true) {
            if (INSTANCE.get() == null) {
                INSTANCE.compareAndSet(null, new Singleton06());
            }
            return INSTANCE.get();
        }
    }
    private Singleton06(){

    }
}
